﻿Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Web
Imports Forecast.Logica.Enumeradores
Imports Forecast.Logica.Modelos

Namespace Servicios
    Public Class ServUsuarios
        Implements IServUsuarios
        
        Public Function ObtenerUsuarioPorUserPassword(username As String, password As String) As Usuario Implements IServUsuarios.ObtenerUsuarioPorUserPassword
            Dim cmd As New SqlCommand()
            Dim da As SqlDataAdapter
            'Dim ds As DataSet
            Dim drReader As SqlDataReader

            Dim conection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString)
            conection.Open()

            cmd.Connection = conection
            cmd.CommandText = "FC_Usuario_Login"
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add("@Username", Data.SqlDbType.VarChar)
            cmd.Parameters("@Username").Value = username
            cmd.Parameters.Add("@Password", Data.SqlDbType.VarChar)
            cmd.Parameters("@Password").Value = password

            ' da = New SqlDataAdapter()
            drReader = cmd.ExecuteReader()

            Dim usuario = New Usuario()

            While drReader.Read()
                If (drReader("IdUsuario") IsNot System.DBNull.Value) Then
                    usuario.IdUsuario = drReader("IdUsuario").ToString()
                End If
                If (drReader("Username") IsNot System.DBNull.Value) Then
                    usuario.Username = drReader("Username").ToString()
                End If
                If (drReader("IdRole") IsNot System.DBNull.Value) Then
                    usuario.idRole = drReader("IdRole").ToString()
                End If
                If (drReader("DesRole") IsNot System.DBNull.Value) Then
                    usuario.DesRole = drReader("DesRole").ToString()
                End If
                If (drReader("Name") IsNot System.DBNull.Value) Then
                    usuario.Name = drReader("Name").ToString()
                End If
                If (drReader("IdEntityF") IsNot System.DBNull.Value) Then
                    usuario.IdEntityF = drReader("IdEntityF").ToString()
                End If
                If (drReader("DesEntity") IsNot System.DBNull.Value) Then
                    usuario.DesEntity = drReader("DesEntity").ToString()
                End If
                If (drReader("Active") IsNot System.DBNull.Value) Then
                    usuario.Active = drReader("Active").ToString()
                End If

            End While

            drReader.Close()
            Return usuario


        End Function

    End Class
    Public Interface IServUsuarios
        Function ObtenerUsuarioPorUserPassword(username As String, password As String) As Usuario
        

    End Interface


End Namespace



